package com.kili.mirco.spark_als.ref.delegate;

import com.kili.mirco.spark_als.com.ModuleType;
import com.kili.mirco.spark_als.init.InitClassConfig;
import com.kili.mirco.spark_als.ref.Processor;
import com.kili.mirco.spark_als.ref.factory.ModelFactory;
import com.kili.mirco.spark_als.ref.factory.RecommendFactory;
import com.kili.mirco.spark_als.ref.hanlder.RecommendProcessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import static com.kili.mirco.spark_als.com.ModuleType.MFM;

/**
 * The delegate class is used to mimic the factoryBean.
 * Handling additional services at startup, and also
 * reducing the intrusion of WEB layer injection code for easy management
 *
 * @date 19-6-10
 * @auther jackliang
 * @description TODO
 */
@Component
@Slf4j
public class MFMDelegator implements Delegation<Processor> {


    private RecommendFactory modelFactory;

    public RecommendProcessor mfm_delegator;


    public MFMDelegator() {
        try {
            this.modelFactory = BeanUtils.instantiateClass(ModelFactory.class, RecommendFactory.class);
        } catch (Exception e) {
            log.error("Initilized class for factory is erorr .[" + RecommendFactory.class.getSimpleName() + "]", e);
            System.exit(-1);
        }
        mfm_delegator = this.doDelegate(MFM);
    }


    @Override
    public RecommendProcessor doDelegate(ModuleType var) {
        return this.modelFactory.getInstance(InitClassConfig.getProperty(var));
    }

}
